import {getGoodInfo} from "../../../HTTP/api/goods";
import {ElMessage} from "element-plus";
const state = {
    goods_info: '',
    goods_size: '',
    goods_detail: '',
    edition:''
}
const mutations = {
    get_goodsInfo: (state, goods_info) => {
        state.goods_info = goods_info
    },
    get_goodsSize: (state, goods_size) => {
        state.goods_size = goods_size
    },
    get_goodsDetail: (state, goods_detail) => {
        state.goods_detail = goods_detail
    },
    get_edition:(state,edition)=>{
        state.edition=edition
    }
}
const actions={
    //获取商品信息
    ReceiveGoodInfo({commit},id){
        let goods_info={}
        let goods_size={}
        let goods_detail=""
        getGoodInfo({good_id:id}).then(res=>{
            if(res.code!==2000){
                ElMessage.error("请求出错")
            }else {
                goods_info.goods_name=res.data.good_name
                goods_info.goods_type=res.data.type_id
                goods_info.goods_img=res.data.img
                goods_info.type_parent_id=res.data.type_parent_id
                goods_size.price=res.data.price
                goods_size.edition=res.data.info[0]?res.data.info[0].edition : ""
                goods_size.weight=res.data.info[0]?res.data.info[0].weight :""
                goods_detail=res.data.info[0].info
                commit('get_goodsInfo',goods_info)
                commit('get_goodsSize',goods_size)
                commit('get_goodsDetail',goods_detail)
            }
        })
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
